Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
React.js - Unique "Key" prop when updating

When I load my page, eveything is fine. When a new show is added, the error appears. Every has a key, I searched all the questions and blogs but can't get it right!

ShowsDisplay.js

import styles from "./ShowsDisplay.module.css";

function ShowsDisplay ({shows, deleteShow}) {
    if (shows.length === 0) {
        return (
            <div key={"nenhumshow"}>
                <p>Nenhum show listado</p>
            </div>
        );
    }
    return (
        <div key={"showsencontrados"}>
            {shows.map((show) => {
                return (
                    <div key={show.id} className={styles.showsDisplay}>
                        <p className={styles.showsTitles}> {show.title}</p>
                        <button className={styles.deleteButton} type="button" onClick={ () => deleteShow(show) }>Delete</button>
                    </div>
                );
            })}
        </div>
    );
}


export default ShowsDisplay;

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try making key as much unique for each child element as you can . Key is the property which tells React DOM , which child element is updated/deleted/added .

{shows.map((show,index) => {
                return (
                    <div key={show.id+" "+ index} className={styles.showsDisplay}>
                        <p className={styles.showsTitles}> {show.title}</p>
                        <button className={styles.deleteButton} type="button" onClick={ () => deleteShow(show) }>Delete</button>
                    </div>
                );
            })}
about 4 years ago · Juan Pablo Isaza Report

0

It must be about the new show, probably the new show's id is undefined so you get that error

if your id is not number in a row try this

{shows.map((show,index) => {
                return (
                    <div key={show.id??index} className={styles.showsDisplay}>
                        <p className={styles.showsTitles}> {show.title}</p>
                        <button className={styles.deleteButton} type="button" onClick={ () => deleteShow(show) }>Delete</button>
                    </div>
                );
            })}

Or just this ''

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!